package com.yx.pojo;

import java.io.Serializable;

public class Result<T> implements Serializable {

    private static final long serialVersionUID = -8746252662382464112L;
    /**
     * 成功标志
     */
    private boolean success;

    /**
     * 消息
     */
    private String message;

    /**
     * 返回代码 0-成功 1-失败 2-参数错误 3-服务未开通
     */
    private String errorcode;

    /**
     * 时间戳
     */
    private long timestamp = System.currentTimeMillis();

    /**
     * 结果对象
     */
    private T data;

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getErrorcode() {
        return errorcode;
    }

    public void setErrorcode(String errorcode) {
        this.errorcode = errorcode;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

        /**
     * 创建错误响应
     * @param msg 错误信息
     * @return Result<T>
     */
    public static <T> Result<T> error(String msg) {
        Result<T> result = new Result<>();
        result.setSuccess(false);
        result.setMessage(msg);
        result.setErrorcode("1");
        return result;
    }

    /**
     * 创建成功响应
     * @param msg 成功信息
     * @return Result<T>
     */
    public static <T> Result<T> success(String msg) {
        Result<T> result = new Result<>();
        result.setSuccess(true);
        result.setMessage(msg);
        result.setErrorcode("0");
        return result;
    }
}
